new Vue({
	el: '#app',
	data() {
		return {
			name: null,
			nickName: null,
			r18_key: null,
			hitokototext: "♪ 听音乐~放松一下 φ(≧ω≦*)♪",
			r18_key_json: null,
			r18Menu: '开启r18',
			r18Icon: 'el-icon-view',
			tabPosition: 'top',
			face_size: 70,
			dialogVisible: false,
			dialogNickName: false,
			dialogr18: false,
			dialogr18Msg: false,
			drawerMagnet: false,
			drawerPlayLlis: false,
			dialogNotice: false,
			r18: false,
			isCloseMM: "noCMM",
			agentIcon: '',
			mobile_flag: false,
			localName: 'user_1.1',
			Removemargin: 'Removemargin',
			pageNum: 0,
			mServerList: [], //所有音乐平台  json
			music: {
				//默认歌单
				server: 'netease',
				id: '6719896607'
			},
			//自定义歌单
			newMusic: {
				server: '',
				id: ''
			},
			carouselHei: "500",
			//地址数据
			address: [], //用来接收json
			addressTypeList:[],
			//图片链接
			picLinks: [], //用来接收json
			picLink: [], //分页数据
			//随机图片api
			ReAPIList: [], //用来接收json
			//本站说明数据
			sundries: [],
			//歌单整理
			PlayList: [], //用来接收json
			//磁力数据
			MagnetList: [] //用来接收json
			//mOptionList:[],//搜索条件
			//timeKey:''
		}
	},
	created: function() {

		this.getJson() //获取数据
		this.getIP(0)
		//判断是否移动端
		this.getEquipment()
		//判断当前用户是否已经开启r18
		var r = localStorage.getItem('RFIHIW_NFIUSSD_KN3MF1E_T8')
		$.get("./StaticData/Key.json").then(res => {
			this.r18_key_json = res
			if (r != null && (r == res.key_xt || r == res.key_sd)) {
				//用户已开启
				this.r18 = true
				this.r18Menu = '关闭r18'
				this.r18Icon = 'el-icon-circle-close'
			} else {
				this.r18 = false
				this.r18Menu = '开启r18'
				this.r18Icon = 'el-icon-view'
			}
		})
		//判断本地是否有自定义歌单
		var cusMusicServ = localStorage.getItem("CUS_MUSIC_SERVER")
		var cusMusicId = localStorage.getItem("CUS_MUSIC_ID")
		if (cusMusicServ != null && cusMusicId != null) {
			this.music.server = cusMusicServ
			this.music.id = cusMusicId
		}
	},
	methods: {
		getJson() {
			$.get('./StaticData/Sundries.json').then(res => {
				this.sundries = res
			})
			$.get('./StaticData/Address.json').then(res => {
				this.addressTypeList = res
				this.isMobile()
			})
			$.get('./StaticData/Links.json').then(res => {
				this.picLinks = res
				this.handleCurrentChange(1)
			})
			$.get('./StaticData/RandomPicAPI.json').then(res => {
				this.ReAPIList = res.apiStrList
			})
			$.get('./StaticData/MusicServer.json').then(res => {
				this.mServerList = res
			})
			$.get('./StaticData/PlayList.json').then(res => {
				this.PlayList = res
			})
			this.carChange(); //初始获取hitokoto 
		},
		//提交自定义歌单
		savaMusic(isdef_flag) {
			var v = this
			if (!isdef_flag) {
				if (this.newMusic.server == '' || this.newMusic.server == null) {
					
					layer.msg('你还没有选择平台！', {
						icon: 7,
						time: 2000
					})
				} else if (this.newMusic.id == '' || this.newMusic.id == null) {
					
					layer.msg('你还没有输入歌单id！', {
						icon: 7,
						time: 2000
					})
				} else if (this.newMusic.id == this.music.id && this.newMusic.server == this.music.server) {
					layer.msg('该歌单已是当前歌单！', {
						icon: 7,
						time: 2000
					})
				} else {
					localStorage.setItem('CUS_MUSIC_SERVER', this.newMusic.server)
					localStorage.setItem('CUS_MUSIC_ID', this.newMusic.id)
					this.isCloseMM = "modal"
					layer.msg('已切换歌单 ヾ(≧▽≦*)o',{time:2500}, function() {
						v.reload()
					})
				}
			} else {
				if (this.music.id == '6719896607' && this.music.server == 'netease') {

					layer.msg('目前已是默认歌单！', {
						icon: 7,
						time: 2000
					})
				} else {

					localStorage.removeItem('CUS_MUSIC_SERVER')
					localStorage.removeItem('CUS_MUSIC_ID')
					this.isCloseMM = "modal"
					layer.msg('已切换为默认歌单',{time:2500}, function() {
						v.reload()
					})
				}
			}

		},
		handleCurrentChange(page) {
			//page:当前页码
			var list = []
			var count = this.picLinks.length
			this.pageNum = Math.ceil(count / 20)
			var end = count - ((page - 1) * 20) - 1
			for (var i = 0; i < 20; i++) {
				if (typeof(this.picLinks[end - i]) != 'undefined') {
					list[i] = this.picLinks[end - i]
				}
			}
			return this.picLink = list
		},
		reload() {
			location.reload()
		},
		//获取当前设备
		getEquipment() {
			var userAgentInfo = navigator.userAgent
			var mobileAgents = ["Android", "iPhone", "SymbianOS", "Windows", "iPad", "iPod", "Mac", "linux",
				"Windows Phone"
			]
			//根据userAgent判断是否是手机
			for (var v = 0; v < mobileAgents.length; v++) {
				if (userAgentInfo.indexOf(mobileAgents[v]) > 0) {
					if (v == 0) {
						this.agentIcon = 'fa fa-android'
					} else if (v == 1) {
						this.agentIcon = 'fa fa-apple'
					} else if (v == 2) {
						this.agentIcon = 'fa fa-mobile'
					} else if (v == 3) {
						this.agentIcon = 'fa fa-windows'
					} else if (v == 4) {
						this.agentIcon = 'fa fa-tablet'
					} else if (v == 5) {
						this.agentIcon = 'fa fa-podcast'
					} else if (v == 6) {
						this.agentIcon = 'fa fa-safari'
					} else if (v == 7) {
						this.agentIcon = 'fa fa-linux'
					} else if (v == 8) {
						this.agentIcon = 'fa fa-mobile'
					} else {
						this.agentIcon = 'fa fa-question-circle-o'
					}
				}
			}
		},
		isMobile() {
			var userAgentInfo = navigator.userAgent
			var mobileAgents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"]
			for (var v = 0; v < mobileAgents.length; v++) {
				if (userAgentInfo.indexOf(mobileAgents[v]) > 0) {
					//如果是移动端...
					this.mobile_flag = true
					this.carouselHei = "250" //轮播高度
					this.face_size = 45 //头像大小
					//$(".container-fluid>.nav-row>.nav-content>.el-main").addClass("el-main-padding020") //删除el-main左右外边距

					this.Removemargin = "Removemargin14px" //hitokoto大小
					break
				}
			}
		},
		getIP(i) {
			localStorage.removeItem('user') //删除上一个版本的user
			var user = localStorage.getItem(this.localName)
			if (user == null || i == 1) {
				var v = this
				if (user == null) {
					this.dialogVisible = true
				}
				var ip = returnCitySN["cip"]
				$.ajax({
					type: 'get',
					url: 'http://api.map.baidu.com/location/ip?ak=rg3c2fj4QBZwa6v3h1w95Sp9&ip=' + ip,
					dataType: 'jsonp',
					success: function(res) {
						console.log(res)
						v.name = res.content.address_detail.city + '的用户' + 100 * Math.random()
						localStorage.setItem(v.localName, v.name)
						v.$message({
							type: 'success',
							message: '欢迎你:' + v.name
						})
						//location.reload()
						return
					},
					error: function(res) {
						v.$message({
							type: 'error',
							message: '地址请求失败！'
						})
						v.name = '火星市的用户'
						localStorage.setItem(v.localName, v.name)
						console.log(res)
					}
				})
			} else {
				this.name = user
				this.$message({
					type: 'success',
					message: '欢迎你:' + user
				})
			}

		},
		//打开设置昵称对话框
		openSetNickName() {
			this.nickName = this.name
			this.dialogNickName = true
		},
		//开启或者关闭r18
		// openR18() {
		// 	var r = localStorage.getItem('RFIHIW_NFIUSSD_KN3MF1E_T8')
		// 	if (r != null && (r == this.r18_key_json.key_xt || r == this.r18_key_json.key_sd)) {
		// 		//已关闭r18 -在不为null的前提下，需要一个key正确才能关闭
		// 		localStorage.removeItem('RFIHIW_NFIUSSD_KN3MF1E_T8')
		// 		this.r18 = false
		// 		this.r18Menu = '开启r18'
		// 		this.r18Icon = "el-icon-view"
		// 		this.$message({
		// 			type: 'success',
		// 			message: '已关闭r18'
		// 		})
		// 	} else {
		// 		this.dialogr18 = true
		// 	}
		// },
		//打开磁力抽屉
		// openDrawerMagnet() {
		// 	this.drawerMagnet = true
		// 	var list = []
		// 	$.get('./StaticData/Magnet.json').then(res => {
		// 		this.MagnetList = res.reverse()
		// 	})
		// },
		// 打开网站预览对话框
		openDialogPreview(url,name) {
			layer.open({
				title:name,
				type: 2,
				content: url,
				area: ["80%", "85%"],
				maxmin: true,
				shade:0,
				resize:false
			})
		},
		//保存昵称按钮
		saveNickName() {
			if (this.nickName == null || this.nickName.trim() == '') {
				layer.msg('昵称为空！', {
					icon: 7,
					time: 2000
				})
			} else if (this.nickName == this.name) {
				layer.msg('未做任何修改！', {
					icon: 7,
					time: 2000
				})
			} else {
				this.name = this.nickName
				localStorage.setItem(this.localName, this.name)
				layer.msg('保存成功！', {
					icon: 1,
					time: 2000
				})
				this.dialogNickName = false
			}
		},
		//幻灯片切换时
		carChange() {
			axios.get('https://v1.hitokoto.cn')
				.then(({
					data
				}) => {
					this.hitokototext = data.hitokoto
				})
				.catch(console.error)
		},
		//验证r18
		// saveR18() {
		// 	//var emailmodel = /^([0-9A-Za-z\-_\.]+)@([0-9a-z]+\.[a-z]{2,3}(\.[a-z]{2})?)$/g;
		// 	if (this.r18_key.trim() == '' || this.r18_key == null) {
		// 		this.$message({
		// 			type: 'error',
		// 			message: '你啥都没输'
		// 		})
		// 	} else if (this.r18_key == this.r18_key_json.key_xt || this.r18_key == this.r18_key_json.key_sd) {
		// 		//已开启r18
		// 		this.r18 = true
		// 		this.r18Menu = '关闭r18'
		// 		this.r18Icon = 'el-icon-circle-close'
		// 		localStorage.setItem('RFIHIW_NFIUSSD_KN3MF1E_T8', this.r18_key)
		// 		this.$message({
		// 			type: 'success',
		// 			message: '已打开R18'
		// 		})
		// 		this.r18_key = null
		// 		this.dialogr18 = false
		// 	} else {
		// 		this.$message({
		// 			type: 'warning',
		// 			message: '群名错误！'
		// 		})
		// 	}
		// },
		showNav() {
			$(".divider-nav .el-card .el-tag").addClass("animate__animated animate__shakeX");
			setTimeout(function() {
				$(".divider-nav .el-card .el-tag").removeClass("animate__animated animate__shakeX");
			}, 1000);
			var $nr = $('.nav-row')
			if ($nr.is(':hidden')) {
				$nr.show();
				layer.msg('已经打开导航区！请往下滑')
			} else {
				$nr.hide();
				layer.msg('关闭了导航区')
			}
		},
		//动画特效区动画特效区动画特效区动画特效区动画特效区动画特效区动画特效区动画特效区动画特效区动画特效区动画特效区动画特效区
		//animate__animated  这是前缀
		//animate__rotateIn 旋转
		//animate__shakeX
		//animate__backInDown
		//animate__flash
		//animate__rubberBand
		//animate__wobble
		//animate__heartBeat
		//animate__jello
		//animate__pulse
		//animate__flipInX
		//animate__bounceOut 从中间弹跳效时
		//animate__fadeOut 渐渐消失
		//animate__zoomOut 渐远消失
		//animate__zoomIn 渐进显示
		addAnimate(name) {
			$("#Animate_" + name).addClass("animate__animated animate__rubberBand");
			setTimeout(function() {
				$("#Animate_" + name).removeClass("animate__animated animate__rubberBand");
			}, 1000);
		},
		// 走马灯点击动画
		carouselAddAnimate() { 
			$('.card-con').fadeOut(1000)
			setTimeout(function() {
				$('.baidu-search').fadeIn(1000)
			}, 1000);
			
		},
		// 点击关闭搜索按钮
		clickSearch() {
			$('.baidu-search').fadeOut(1000)
			setTimeout(function() {
				$(".card-con").fadeIn(1000)
			}, 1000);
		},
		// 头像鼠标悬浮添加动画
		faceAddAnimate() {
			$(".navbar-header a span").addClass("layui-anim layui-anim-rotate");
			setTimeout(function() {
				$(".navbar-header a span").removeClass("layui-anim layui-anim-rotate");
			}, 1000);
			
		},
		// 访问量图片动画
		addVisitsAnimate() {
			$("#Visits_pic").addClass("animate__animated animate__flipInX");
			setTimeout(function() {
				$("#Visits_pic").removeClass("animate__animated animate__flipInX");
			}, 1000);
		}
	}
});
